package com.baosight.demo.bean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MethodInfo {
    public String commentContent;
    public String methodName;
    public String returnType;
    public List<ParamInfo> paramInfoList;
    public String methodComment;
    public String returnComment;

    public MethodInfo(String commentContent, String methodName, String returnType, List<ParamInfo> paramInfoList) {
        this.commentContent = commentContent;
        this.methodName = methodName;
        this.returnType = returnType;
        this.paramInfoList = paramInfoList;
    }

    public String getMethodComment() {
        return methodComment;
    }

    public String getReturnComment() {
        return returnComment;
    }

    public String getCommentContent() {
        return commentContent;
    }

    public void setCommentContent(String commentContent) {
        this.commentContent = commentContent;

    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public String getReturnType() {
        return returnType;
    }

    public void setReturnType(String returnType) {
        this.returnType = returnType;
    }

    public List<ParamInfo> getParamInfoList() {
        return paramInfoList;
    }

    public void setParamInfoList(List<ParamInfo> paramInfoList) {
        this.paramInfoList = paramInfoList;
    }

    public void init(){

        StringBuffer methodC=new StringBuffer("");
        StringBuffer returnC=new StringBuffer("");
        StringBuffer paramC=new StringBuffer("");
        Map<String,String> paramInfo=new HashMap<>();
        int commentStatus=0;

        String paramName=null;
        for(String line:commentContent.replace("*","").split("\r\n")){
            line=line.trim();
            if(line.length()==0){
                continue;
            }
            if(line.startsWith("@param")){
                commentStatus=1;
                String[] splitLine = line.split("\\s+");
                if(splitLine.length>1) {
                    paramName = splitLine[1];
                }
            }else if(line.startsWith("@return")){
                commentStatus=2;
            }
            switch (commentStatus){
                case 0:
                    methodC.append(line);
                    break;
                case 1:

                    break;
                case 2:
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    public String toString() {
        return "MethodInfo{" +
                "commentContent='" + commentContent + '\'' +
                ", methodName='" + methodName + '\'' +
                ", returnType='" + returnType + '\'' +
                ", paramInfoList=" + paramInfoList +
                '}';
    }
}

